/**
 * 离开提示
 */
define( [
	'jquery',
	'../../modules/autoSave',
	'../editorCollect/subDataCheck',
	'../../lib/editData'
], function( $, AutoSave, sdc, editData ) {
	var $leaveConfirm = $( '#leaveConfirm' );

	function leaveDo() {
		window.onbeforeunload = function( event ) {
			return null;
		}
		AutoSave.clear();
		location.href = $( '.nav-title-bg .title' ).attr( '_href' );
	}
	// 保存
	$leaveConfirm.on( 'click', '.modal-footer > .ok', function() {
		sdc.doSaveGraph( leaveDo );
	} ).on( 'click', '.modal-footer > .cancel', leaveDo ); // 不保存

	$( document ).on( 'click', '.nav-title-bg>.title', function() {
		if ( editData.isContentChange ) {
			$leaveConfirm.modal( "show" );
		} else {
			location.href = $( this ).attr( '_href' );
		}
	} );

	window.onbeforeunload = function( event ) {
		if ( editData.isContentChange ) {
			return '即将离开页面，请确认您编辑的内容已经保存';
		}
	};
} );